#include "shooter_clutch.h"

/* 射箭机构上的离合器/刹车片 */

void shooter_clutch_init(shooter_clutch_t *clu, void *port, uint16_t pin)
{
    clu->port = port;
    clu->pin = pin;
}

void shooter_clutch_set_lock(shooter_clutch_t *clu)
{
    if (clu->lock != SHOOTER_CLUTCH_LOCK) {
        HAL_GPIO_WritePin(clu->port, clu->pin, GPIO_PIN_SET);
        clu->lock = SHOOTER_CLUTCH_LOCK;
    }
}

void shooter_clutch_set_unlock(shooter_clutch_t *clu)
{
    if (clu->lock != SHOOTER_CLUTCH_UNLOCK) {
        HAL_GPIO_WritePin(clu->port, clu->pin, GPIO_PIN_RESET);
        clu->lock = SHOOTER_CLUTCH_UNLOCK;
    }
}

int shooter_clutch_is_locked(shooter_clutch_t *clu)
{
    return clu->lock;
}